# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:download_file1_0.py
@Time:2024/10/30 19:55

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""

import requests
import os
import sys

# 指定要下载的文件的URL
url = 'https://chromedriver.storage.googleapis.com/109.0.5414.74/chromedriver_win32.zip'
# https://chromedriver.storage.googleapis.com/109.0.5414.74/chromedriver_win32.zip

# 指定本地保存文件的文件夹和文件名
# local_folder = 'D:/code_zgq/ganbu/Download'
local_folder = os.path.dirname(os.path.realpath(sys.argv[0]))+'/Download'
print(local_folder)
local_filename = 'chromedriver_win32.zip'

# 确保本地文件夹存在
if not os.path.exists(local_folder):
    os.makedirs(local_folder)

# 构建本地文件的完整路径
local_filepath = os.path.join(local_folder, local_filename)

# 发送HTTP GET请求下载文件
try:
    response = requests.get(url, stream=True)
    response.raise_for_status()  # 如果请求出错，这里会抛出HTTPError异常

    with open(local_filepath, 'wb') as f:
        for chunk in response.iter_content(chunk_size=8192):
            f.write(chunk)

    print(f'文件已成功保存到 {local_filepath}')
except requests.RequestException as e:
    print(f'下载文件时出错: {e}')